 @extends('layouts.art')
@section('content')

<form class="form-horizontal"  id="avatar">
		   {{ csrf_field() }}
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">名字</label>
    <div class="col-sm-8">
      <input type="title" class="form-control" id="title" name="title">
    </div>
  </div>


  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">头像</label>
    <div class="col-sm-8">
        <input type="file" class="form-control" id="title" name="photo">
    </div>
  </div>
   
  
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <a  class="btn btn-default" onclick="uploadInfo()">上传</a>
    </div>
  </div>
</form>

<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
function uploadInfo() {  
     var formData = new FormData($("#avatar"));  
     $.ajax({  
          url: "{{url('photo')}}",
          type: 'POST',  
          data: formData,  
          contentType: false,  
          processData: false,  
          success: function (returndata) {  
              console.log(returndata);  
          },  
          error: function (returndata) {  
              console.log(returndata);  
          }  
     });  
}  

</script>

@endsection



<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<form id= "uploadForm">  
		 {{ csrf_field() }}
      <p >指定文件名： <input type="text" name="filename" value= ""/></p >  
      <p >上传文件： <input type="file" name="photo"/></ p>  
      <input type="button" value="上传" onclick="doUpload()" />  
</form>  

<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$.ajaxSetup({
    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
});

function doUpload() {  
	
     var formData = new FormData($( "#uploadForm" )[0]);  
     $.ajax({  
             url: "{{url('photo')}}",
          type: 'POST',  
          data: formData,  
          async: false,  
          cache: false,  
          contentType: false,  
          processData: false,  
          success: function (returndata) {  
              console.log(returndata);  
          },  
          error: function (returndata) {  
              console.log(returndata);  
          }  
     });  
}  

</script>
</body>
</html>